<!--
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2024-03-05 15:06:47
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2024-03-14 09:43:32
 * @FilePath: /hr_new_vue3/src/views/Management/Organization/OrganizationManagement/Structure/MoveMergeHistory/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 移动/合并历史 -->
<template>
  <ContentCard>
    <template #header>
      <PageHeaderNew :title="`${type === 2 ? '移动' : '合并'}历史`" showBack />
    </template>
    <table-turn :table-data="getTableData" ref="tableRef">
      <a-table-column :width="80">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column
        :width="200"
        data-index="reMergeOrganizationName"
        :title="`被${type === 2 ? '移动' : '合并'}组织`"
      />
      <a-table-column
        :width="200"
        data-index="createName"
        :title="`${type === 2 ? '移动' : '合并'}人`"
      />
      <a-table-column
        :width="200"
        data-index="createdAt"
        :title="`${type === 2 ? '移动' : '合并'}时间`"
      >
        <template #cell="{ record }">{{
          dayjs(record.createdAt).format('YYYY-MM-DD HH:mm:ss')
        }}</template>
      </a-table-column>
      <a-table-column :width="100" data-index="" title="操作" fixed="right">
        <template #cell="{ record }">
          <a-space :size="0">
            <a-button type="text" @click="goChange(record.id)"
              >人事异动</a-button
            >
            <a-button type="text" @click="goDetail(record.id)"
              >查看详情</a-button
            >
          </a-space>
        </template>
      </a-table-column>
    </table-turn>
  </ContentCard>
</template>

<script lang="tsx" setup>
import { Message } from '@arco-design/web-vue';
import { GetMergeOrganizationListHistory } from '@/apis/management/organization/organizationManagement';
import dayjs from 'dayjs';

const router = useRouter();
const route = useRoute();

const type = +route.params.type; // 1 合并 2 移动
const id = +route.params.id;

let tableRef = ref();
// 获取表格数据
const getTableData = async (pageData?: any) => {
  try {
    const res = await GetMergeOrganizationListHistory({
      id,
      type,
      ...pageData
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};
// 前往人事异动
const goChange = (id: number) => {
  router.push({
    name: 'OrganizationPersonChange',
    params: {
      id,
      type
    }
  });
};

// 前往设置变更
const goDetail = (id: number) => {
  router.push({
    name: 'OrganizationPersonChangeDetail',
    params: {
      id,
      type
    }
  });
};

// 刷新表格数据
const refresh = () => {
  tableRef.value.loadData();
};
</script>

<style scoped lang="less"></style>
